/**
    ==================================================================================================
**    date: 2007.8.20
**    author: kuanglingxuan
**    description: ajax united select
**  ==================================================================================================
**/
var j;
	/**
	*	parse xml then build option
	*/
	function parseXmlBuildOptions(xml, targetId){

		var xmlEle = xml.documentElement;
	//	alert(xmlEle)
		var dataList = new Array();
		if (xmlEle) dataList = xmlEle.getElementsByTagName('select-node');
		var targetObj = document.getElementById(targetId);

		if(j == undefined){
			if(targetObj.options[0].value == ''){
					j = 1;
			}else{
					j = 0;
			}
		}
			targetObj.options.length=j;

	//	alert(j);
		var dataLen = dataList.length;

		if(dataLen == 0 && j == 0){
			var optionObj = document.createElement("option");
			var textObj = document.createTextNode("无");
			optionObj.appendChild(textObj);
			targetObj.appendChild(optionObj);
			targetObj.options[0].value='';
			return;
		}

		for (i = 0; i < dataLen; i++) {


	//		alert(targetObj);
			var nodeText = dataList[i].childNodes[0].firstChild.nodeValue;//.firstChild;
	//		alert(dataList[i].childNodes[0].firstChild.nodeValue);
	//		alert(dataList[i].childNodes.length);
			var nodeId = dataList[i].childNodes[1].firstChild.nodeValue;
			var optionObj = document.createElement("option");
			var textObj = document.createTextNode(nodeText);
			optionObj.appendChild(textObj);
			targetObj.appendChild(optionObj);
			targetObj.options[i+j].value=nodeId;
		}

	}

	/**
	*	ajax part
	*/
 	function send_request(url, targetId,callback){
	     var http_request=false;

	     if(window.XMLHttpRequest){//Mozilla
	         http_request=new XMLHttpRequest();
	         if(http_request.overrideMimeType){
	             http_request.overrideMimeType("text/xml");
	         }
	     }
	     else if(window.ActiveXObject){//IE
	         try{
	             http_request=new ActiveXObject("Msxml2.XMLHTTP");
	         }
	         catch(e){
	             try{
	                 http_request=new ActiveXObject("Microsoft.XMLHTTP");
	             }
	             catch(e){}
	         }
	     }

	     if(!http_request){
	         window.alert("can't create XMLHttpRequest!");
	         return false;
	     }

	     http_request.onreadystatechange=function(){processRequest(http_request,targetId,callback)};

	     http_request.open("POST",url,true);
	     http_request.send(null);
	 }

	 function processRequest(http_request,targetId,callback){

	     if(http_request.readyState==4){

	         if(http_request.status==200){

				var str = http_request.responseText;
				var xml = http_request.responseXML;


				if(xml != null){


					parseXmlBuildOptions(xml, targetId);

					if(window.ajaxSelectCallBack != undefined)
						window.ajaxSelectCallBack(xml);

                   eval(callback);


				}
			}

	    }


	 }

	/**
	*	onchange method
	*/
	function onChangeSelect(url, selectId, targetId,callback){

		var targetObj = document.getElementById(targetId);
		if(targetObj != null){
			targetObj.options.length=1;
			//	targetObj.onchange;
				targetObj.options[0].selected = true;
				if(window.ActiveXObject){//IE
			     targetObj.fireEvent('onchange');
			    }else{
			     targetObj.onchange();
			    }

			if(selectId == null || selectId == ''){

				if(window.ajaxSelectCallBack != undefined)
					window.ajaxSelectCallBack();
				return;
			}else{

				send_request(url+"&time="+new Date().getTime(), targetId,callback);
			}

		//	targetObj.fireEvent('onchange');
		}


	 }




